

//function ready(callback) {
//    // 如果 jsbridge 已经注入则直接调用
//    if (window.AMAPJSBridge) {
//      callback && callback();
//    } else {
//      // 如果没有注入则监听注入的事件
//      alert("AMAPJSBridgeReady");
//
//        document.addEventListener('AMAPJSBridgeReady', function(data){
//                  console.warn('titleClick'+JSON.stringify(data));
//                });
//    }
//  }
//
//
//ready(function (data) {
//
//
//  }
//)
function callFuncInWeb(params) {
    console.warn("来自原生的数据="+params);
    return "JS return结果"
}
function callFuncInWeb2(params) {
    console.warn("来自原生的数据="+params);
}
function callToApp() {
    if (window.JSAndroid && window.JSAndroid.call) {
        var result = JSAndroid.call("message from web");
        console.warn(result);
    }
}
var amapvalue = {
    sql: "INSERT INTO user(name,age) VALUES('大白','10')"
};

function jsapi_call(apiName, params) {

    AMAPJSBridge.call(apiName, params, function (data) {

        console.warn(JSON.stringify(data));

    });
}
function jsapi_callSync(apiName,params){
    let result = AMAPJSBridge.callSync(apiName,params);
    console.warn(JSON.stringify(result));
}
function jsapi_call1(apiName, params) {

    AMAPJSBridge.call(apiName, params, function (data) {

        alert(JSON.stringify(data));

    });
}
function jsapi_call_showLoading() {
    window.AMAPJSBridge && AMAPJSBridge.call('showLoading');
    setTimeout("window.AMAPJSBridge && AMAPJSBridge.call('hideLoading')", 3000);
}

function jsapi_call_showToolbar() {
    window.AMAPJSBridge && AMAPJSBridge.call('showLoading');
    setTimeout("window.AlipayJSBridge && AMAPJSBridge.call('hideLoading')", 3000);
}

function jsapi_call_actionSheet() {
    window.AMAPJSBridge && AMAPJSBridge.call('actionSheet', {
        'title': '标题',
        'btns': ['第一个按钮', '第二个按钮', '第三个按钮'],
        'cancelBtn': '取消',
        'destructiveBtnIndex': 2
    }, function (data) {
        switch (data.index) {   // index标示用户点击的按钮，在actionSheet中的位置，从0开始
            case 0:
                alert('第一个按钮');
                break;
            case 1:
                alert('第二个按钮');
                break;
            case 2:
                alert('第三个按钮');
                break;
            case 3:
                alert('取消按钮');
                break;
        }
    });
}


document.addEventListener('toolbarMenuClick', function (data) {
    alert('调用结果' + JSON.stringify(data));
    setTimeout("window.AMAPJSBridge && AMAPJSBridge.call('hideToolbar')", 0);
});
function custom_jsapi_test() {
    window.AMAPJSBridge && AMAPJSBridge.call('pushWindow', { 'url': 'H5JsApiTest.html' }, function (data) {
        alert('调用结果' + JSON.stringify(data));
    });

}



document.addEventListener('resume', function (event) {
    alert('页面回退时带过来的内容： ' + JSON.stringify(event.data));
});

document.addEventListener('nativeEvent', function (e) {
    alert('nativeEvent带过来的内容： ' + JSON.stringify(e));
}, false);
document.addEventListener('AMAPSendMessageToAliPayRespEvent', function (data) {
    alert('支付宝分享结果' + JSON.stringify(data));
});

var audioPath = '';
function startAudio() {
    AMAPJSBridge.call('startAudio', function (result) {
        if (result.code == '1') {
            audioPath = result['data']['path'];
        }
        alert(JSON.stringify(result));
    });
}

function playAudio() {
    AMAPJSBridge.call('playAudio', {
        audioPath: audioPath
    }, function (result) {
        alert(JSON.stringify(result));
    });
}

function signature() {
    AMAPJSBridge.call('signature', function (result) {
        if (result.code == '1') {

        }
        alert(JSON.stringify(result));
    });
}

var watermarkImagePath;
function getPhoto() {
    var params = {
        "isEdit": false,
        "pixeLW": "300",
        "pixeLH": "300"
    }
    AMAPJSBridge.call('getPhoto', params, function (result) {
        if (result.code == '1') {
            watermarkImagePath = result['data']['filePath'];
            //        $Image('imageb').setUrl(result['data']['filePath']);

            var filename = watermarkImagePath.substring(watermarkImagePath.lastIndexOf('/') + 1, watermarkImagePath.length);
            var parmObj = {
                postadress: 'http://113.200.158.218:10003/NGOSS_ORDERAPP/BYD_Image_01',
                tabfile: [watermarkImagePath],
                tabname: [filename],
                isReplaceURL: '0',
                isReturnAll: '1',
                param: {
                    FILENAME: filename,
                    SUBTYPE: 'SQ1004',
                    SCANOPERATOR: 'bydbj047j',
                    DOCCODE: 'BX-A783894000',
                    NUMPAGES: '1',
                    PAGENO: 'PAGENO'
                }
            };
            AMAPJSBridge.call('cdv_fileUpload', parmObj, function (result) {
                alert(JSON.stringify(result));
            });

        }
        // alert(JSON.stringify(result));
    });
}


function openLocalFile() {

    AMAPJSBridge.call('cdv_fileDownLoad', {
        "downloadadress": ["http://192.9.200.100:50003/downService/downloadFile?isAbsolutePath=true&filePath=file/classfile/179/b463fc19-1507-418e-a56a-1ba686f7815a/需求.doc"],
        "fileType": [".doc"],
        "isReplaceURL": "0",
        "timeout": "30",
        "isExternal": "true"
    }, function (result) {
        var filepath = result.data.files
        alert(filepath[0])

        AMAPJSBridge.call('openLocalFile', {
            "filePath": filepath[0]
        }, function (result) {
            alert(JSON.stringify(result));
        });

    });
}
function getMovie() {
    var params = {
        "qulity": "1",
        "pixeLW": "400",
        "pixeLH": "400"
    }
    AMAPJSBridge.call('getMovie', params, function (result) {
        if (result.code == '1') {
            //        $Image('imagec').setUrl(result.data.imageSmall);
        }
        alert(JSON.stringify(result));
    });
}

function makeImg() {
    var params = {
        "content": "11111111",
        "type": "1"
    }
    AMAPJSBridge.call('makeImg', params, function (result) {
        if (result.code == '1') {
            //        $Image('imaged').setUrl(result.data);
        }
        alert(JSON.stringify(result));
    });
}

function watermark() {
    var params = {
        "imagePath": watermarkImagePath,
        "text": "加水印",
        "textsize": "20",
        "location": "2",
    }
    if (!params['imagePath']) {
        alert('请先拍照或选择照片');
        return;
    }
    AMAPJSBridge.call('watermark', params, function (result) {
        if (result.code == '1') {
            //        $Image('imagee').setUrl(result.data.filePath);
        }
        alert(JSON.stringify(result));
    });
}

function goToListBundle() {
    var value = $InputItem('goToListBundle').getValue()
    var paramObj = {
        "bundleUrl": value,
        "type": "",
        "route": "checker",
        "initialProperties": {
            "route": "aaaaa"
        }
    };
    AMAPJSBridge.call('goToListBundle', paramObj, function (result) {
        // alert(JSON.stringify(result));
    });
}

function goToListBundleLoad() {
    var value = $InputItem('goToListBundle').getValue()
    var paramObj = {
        "bundleUrl": value,
        "isLoading": "true",
        "loadImg": "",
        "loadMsg": "",
        "type": "",
        "route": "index",
        "initialProperties": {
            "route": "searchbar"
        }
    };
    AMAPJSBridge.call('goToListBundle', paramObj, function (result) {
        if (result.code == '1') {
            //        $Label('showLabel').setText(JSON.stringify(result));
        }
    });
}

function goToListBundleH5() {
    var value = $InputItem('goToListBundleH5').getValue()
    var paramObj = {
        "bundleUrl": value,
        "type": "cordova",
        "cordovaType": "02",
        "route": "index.html"
    };
    AMAPJSBridge.call('goToListBundle', paramObj, function (result) {
        // alert(JSON.stringify(result));
    });
}

function iOSgoToListBundle() {
    var value = $InputItem('iOSgoToListBundle').getValue()
    var paramObj = {
        "bundleUrl": value,
        "type": "",
        "route": "",
        "initialProperties": {
            "route": "aaaaa"
        }
    };
    AMAPJSBridge.call('goToListBundle', paramObj, function (result) {
        // alert(JSON.stringify(result));
    });
}

function iOSgoToListBundleLoad() {
    var value = $InputItem('iOSgoToListBundle').getValue()
    var paramObj = {
        "bundleUrl": value,
        "isLoading": "true",
        "loadImg": "",
        "loadMsg": ""
        //          "type":"",
        //          "route":"searchbar",
        //           "initialProperties":{
        //               "route":"searchbar"
        //           }
    };
    AMAPJSBridge.call('goToListBundle', paramObj, function (result) {
        // alert(JSON.stringify(result));
    });
}

function iOSgoToListBundleH5() {
    var value = $InputItem('iOSgoToListBundleH5').getValue()
    var paramObj = {
        "bundleUrl": value,
        "type": "cordova",
        "cordovaType": "02",
        "route": "index.html"
    };
    AMAPJSBridge.call('goToListBundle', paramObj, function (result) {
        // alert(JSON.stringify(result));
    });
}

var filePath;
function saveFile() {
    var obj = {
        content: "7777778jjjj",
        fileName: "dq.txt",
        isEncrypt: "1",
        secretKey: "abcdef0123456789"
    }
    AMAPJSBridge.call('saveFile', obj, function (result) {
        if (result.code == '1') {
            filePath = result.data.filePath;
        }
        alert(JSON.stringify(result));
    });
}

function readFile() {
    var obj = {
        desPath: filePath,
        secretKey: "abcdef0123456789",
        isDecrypt: "1"
    }
    AMAPJSBridge.call('readFile', obj, function (result) {
        alert(JSON.stringify(result));
    });
}

function copyFile() {
    var obj = {
        "srcPath": filePath,
        "desPath": "b/a.txt"
    }
    AMAPJSBridge.call('copyFile', obj, function (result) {
        alert(JSON.stringify(result));
    });
}

function shearFile() {
    var obj = {
        "srcPath": filePath,
        "desPath": "b/shear.txt"
    }
    AMAPJSBridge.call('shearFile', obj, function (result) {
        alert(JSON.stringify(result));
    });
}

function deleteFile() {
    var obj = {
        content: "7777778jjjj",
        fileName: "dq.txt",
        isEncrypt: "1",
        secretKey: "abcdef0123456789"
    }
    AMAPJSBridge.call('saveFile', obj, function (result) {
        if (result.code == '1') {
            filePath = result.data.filePath;
            var obj = {
                "srcPath": filePath
            }
            AMAPJSBridge.call('deleteFile', obj, function (result) {
                alert(JSON.stringify(result));
            });
        }
        alert(JSON.stringify(result));
    });
}

var lineColorType = "1";
function changeFace(info) {
    if (info.checked) {
        lineColorType = "0";
    } else {
        lineColorType = "1";
    }
}

var imagpath;
function picture() {
    AMAPJSBridge.call('picture', {
        photoMaxNum: "5",
        isEdit: true,
        pixeLW: "500",
        pixeLH: "600",
        selectType: "03"
    }, function (result) {
        if (result.code == '1') {
            imagpath = result.data[0].filePath
        }
        setTimeout(function () {
            alert("cordva=" + JSON.stringify(result));
        }, 1000);
    });
}

var shearimagpath;
function shearImage() {
    var parm = {
        "image": imagpath
    };
    AMAPJSBridge.call('shearImage', parm, function (result) {
        if (result.code == '1') {
            shearimagpath = result.data;
        }
        alert(JSON.stringify(result));
    });
}

function saveAlbum() {
    var parm = {
        "image": shearimagpath
    }
    AMAPJSBridge.call('saveAlbum', parm, function (result) {
        alert(JSON.stringify(result));
    });
}

function compressImage() {
    var obj = {
        "imagePath": shearimagpath,
        "type": "2",
        "volume": "1024",
        "width": "300",
        "height": "300"
    }
    AMAPJSBridge.call('compressImage', obj, function (result) {
        if (result.code == '1') {
            imagePath = [];
            imagePath.push(result.data.path);
            //        $Image('image2').setUrl(result.data.path);
        }
        alert(JSON.stringify(result));
    });
}

function imageTobase64() {
    var parm = {
        "image": shearimagpath
    }
    AMAPJSBridge.call('imageTobase64', parm, function (result) {
        alert(JSON.stringify(result));
    });
}

function initHttps() {
    var parm = {
        "initURL": "https://amap.agreechina.com:443/basic/v1/init/getAlgorithm",
        "saveUpSecURL": "https://amap.agreechina.com:443/basic/v1/init/exchangeKey"
    };
    AMAPJSBridge.call('initHttps', parm, function (result) {
        alert(JSON.stringify(result));
    });
}

function post() {
    // 原生params
    //        var parmObj = {
    //        // 原生
    //        url: 'user/v1/sms/code',
    //        params: {
    //        phone:'18610487490'
    //        }
    //        }
    // 原生params
    var parmObj = {
        // 原生
        url: '',
        params: {},
        headers: {
            SERVERCODE: 'demo.service.one',

        }
    }
    AMAPJSBridge.call('netWork', parmObj, function (result) {
        alert(JSON.stringify(result));
    });
}

var url_temp = "";
function addTasks() {
    url_temp = "http://f3.market.xiaomi.com/download/AppStore/08c674eee0f857ed80f0efa9158a6cb021c42957b/com.imibaby.client.apk";
    var param1 = {
        url: 'http://f3.market.xiaomi.com/download/AppStore/08c674eee0f857ed80f0efa9158a6cb021c42957b/com.imibaby.client.apk',
        fileName: '测试下载11111',
        fileType: '.apk'
    };
    var param2 = {
        url: 'https://amap.agreechina.com/dist/logo_small.png',
        fileName: 'logo_small',
        fileType: '.png'
    };
    var param3 = {
        url: 'https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png',
        fileName: 'baidu',
        fileType: '.png'
    };
    var obj = {
        tasks: [param1, param2, param3],
        maxRunningTasks: '3'
    };
    AMAPJSBridge.call('addTasks', obj, function (result) {
        alert(JSON.stringify(result));
    });
}

function queryTasksStatus() {
    var obj = {
        "urls": [url_temp]
    };
    AMAPJSBridge.call('queryTasksStatus', obj, function (result) {
        alert(JSON.stringify(result));
    });
}

function showDownloadCenter() {
    var obj = {
    };
    AMAPJSBridge.call('showDownloadCenter', obj, function (result) {
        alert(JSON.stringify(result));
    });
}

function addCalenderEvent() {
    AMAPJSBridge.call('addCalenderEvent', {
        title: '测试',
        startDate: "2020-10-11 12:05",
        endDate: "2020-10-12 12:05",
        notes: "时间内容",
        rule: "6",
        frequency: "1",
        days: [1, 2],
        amonths: [],

    }, function (result) {
        alert(JSON.stringify(result));
    });
}

var eventIdentifier;
function checkCalenderEvent() {
    var parm = {
        "startDate": "2020-09-11 12:05",
        "endDate": "2020-11-12 12:05"
    };
    AMAPJSBridge.call('checkCalenderEvent', parm, function (result) {
        if (result.code == '1') {
            eventIdentifier = result.data[0].eventIdentifier;
        }
        alert(JSON.stringify(result));
    });
}

function removeCalenderEvent() {
    var parm = {
        "eventIdentifier": eventIdentifier
    };
    AMAPJSBridge.call('removeCalenderEvent', parm, function (result) {
        alert(JSON.stringify(result));
    });
}

function getCallPhone() {
    AMAPJSBridge.call('getCallPhone', {
        phone: "手机号"
    }, function (result) {
        alert(JSON.stringify(result));
    });
}

function sendMessage() {
    var parm = {
        "phones": ["18864500321"],
        "message": "短信内容"
    };
    AMAPJSBridge.call('sendMessage', parm, function (result) {
        alert(JSON.stringify(result));
    });
}

function sendEmail() {
    var stringParameter = {
        to: ["daiqiang@agree.com.cn"],
        cc: ["chengbotao@agree.com.cn"],
        bcc: ["chengbotao@agree.com.cn"],
        subject: "mail",
        body: "hi email test"
    }
    AMAPJSBridge.call('sendEmail', stringParameter, function (result) {
        alert(JSON.stringify(result));
    });
}

function getCallStatusAndTime() {
    AMAPJSBridge.call('getCallStatusAndTime', {
        phone: "18866600326"
    }, function (result) {
        alert(JSON.stringify(result));
    });
}

function ringtong_shake() {
    var params = {
        "type": "0",
        "milliseconds": "1000"
    };
    AMAPJSBridge.call('ringtong_shake', params, function (result) {
        alert(JSON.stringify(result));
    });
}

function AMAPTouchDataID() {
    AMAPJSBridge.call('getDefaults', {
        "key": "AMAPTouchDataID"
    }, function (result) {
        alert(JSON.stringify(result));
    });
}
document.addEventListener('pageResume', function (data) {
    //alert('pageResume'+JSON.stringify(data))
    console.warn('pageResume' + JSON.stringify(data));
});
document.addEventListener('appResume', function (data) {
    //alert('pageResume'+JSON.stringify(data))
    console.warn('appResume' + JSON.stringify(data));
})
document.addEventListener('pagePause', function (data) {
    console.warn('pagePause' + JSON.stringify(data));
});
document.addEventListener('appPause', e => {
    e.preventDefault()
    console.log('appPause' + JSON.stringify(e))
},
    false);

document.addEventListener('titleClick', function (data) {
    console.warn('titleClick' + JSON.stringify(data))
});
document.addEventListener('titleClick', function (data) {
    console.warn('titleClick' + JSON.stringify(data));
});
document.addEventListener("onKeyBoardShow", function (data) {
    alert(JSON.stringify(data))
});

document.addEventListener('onPwdResult', function (data) {
    alert('键盘数据' + JSON.stringify(data));
});

document.addEventListener('AMAPCalendarManageEventReminder', function (data) {
    alert('键盘高度:' + JSON.stringify(data));
});


document.addEventListener("RightOptionMenu", function (e) {
    if (e.data.index == 0) {
        alert(e.data.index)
    } else if (e.data.index == 1) {
        alert(e.data.index)
    }

});
//    document.addEventListener("LeftOptionMenu", function(e) {
//
//            alert(JSON.stringify(e))
//            });
//
//     document.addEventListener('back', function(a){
//         a.preventDefault();
//
//             var params = {
//                    title: '亲',
//                    message: '关闭应用',
//                    button: '确定'
//             };
//            AMAPJSBridge.call('alert', params, function (ccc) {
//
//                   AMAPJSBridge.call('exitH5App',{animated:true});
//             });
//  });

function ready(callback) {
    // 如果 jsbridge 已经注入则直接调用
    if (window.AMAPJSBridge) {
        callback && callback();
    } else {
        // 如果没有注入则监听注入的事件
        document.addEventListener('AMAPJSBridgeReady', callback);
    }
}

ready(function (data) {

}
)




